/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demoswingcontrols;

/**
 *
 * @author mafudge
 */
public class DemoSwingControlsJFrame extends javax.swing.JFrame {

    /**
     * Creates new form DemoSwingControlsJFrame
     */
    public DemoSwingControlsJFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonGroupColors = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabelMessage = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jCheckBoxEatAtJoes = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        jRadioButtonRed = new javax.swing.JRadioButton();
        jRadioButtonBlue = new javax.swing.JRadioButton();
        jRadioButtonGreen = new javax.swing.JRadioButton();
        jLabel6 = new javax.swing.JLabel();
        jComboBoxAnimals = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldMessage = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabelMessageValue = new javax.swing.JLabel();
        jLabelCheckValue = new javax.swing.JLabel();
        jLabelRadioValue = new javax.swing.JLabel();
        jLabelTextValue = new javax.swing.JLabel();
        jLabelComboValue = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Common Java Swing Controls");

        jLabel1.setText("Label");

        jLabelMessage.setText("This is a message");
        jLabelMessage.setToolTipText("");

        jButton1.setText("Click Me");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Button");

        jCheckBoxEatAtJoes.setText("Eat at Joes?");
        jCheckBoxEatAtJoes.setToolTipText("");

        jLabel5.setText("Check");

        jButtonGroupColors.add(jRadioButtonRed);
        jRadioButtonRed.setText("Red");

        jButtonGroupColors.add(jRadioButtonBlue);
        jRadioButtonBlue.setSelected(true);
        jRadioButtonBlue.setText("Blue");

        jButtonGroupColors.add(jRadioButtonGreen);
        jRadioButtonGreen.setText("Green");

        jLabel6.setText("Radio Buttons");

        jComboBoxAnimals.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bird", "Cat", "Dog", "Fish", "Reptile", "Other" }));

        jLabel7.setText("Combo Box");

        jLabel4.setText("Text Field");

        jLabel2.setText("Java Swing Controls");

        jLabel8.setText("Control Values (click the button to change)");

        jLabelMessageValue.setForeground(new java.awt.Color(255, 0, 0));
        jLabelMessageValue.setText("?????");
        jLabelMessageValue.setToolTipText("");

        jLabelCheckValue.setForeground(new java.awt.Color(255, 0, 0));
        jLabelCheckValue.setText("?????");
        jLabelCheckValue.setToolTipText("");

        jLabelRadioValue.setForeground(new java.awt.Color(255, 0, 0));
        jLabelRadioValue.setText("?????");
        jLabelRadioValue.setToolTipText("");

        jLabelTextValue.setForeground(new java.awt.Color(255, 0, 0));
        jLabelTextValue.setText("?????");
        jLabelTextValue.setToolTipText("");

        jLabelComboValue.setForeground(new java.awt.Color(255, 0, 0));
        jLabelComboValue.setText("?????");
        jLabelComboValue.setToolTipText("");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(80, 80, 80)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(89, 89, 89)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel5))
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBoxEatAtJoes)
                            .addComponent(jLabelMessage)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jRadioButtonRed)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jRadioButtonBlue))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(136, 136, 136)
                                .addComponent(jRadioButtonGreen))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addGap(44, 44, 44)
                                        .addComponent(jComboBoxAnimals, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(10, 10, 10)
                                                .addComponent(jLabel3)
                                                .addGap(44, 44, 44)
                                                .addComponent(jButton1))
                                            .addComponent(jLabel4)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(98, 98, 98)
                                        .addComponent(jTextFieldMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelRadioValue)
                    .addComponent(jLabelMessageValue)
                    .addComponent(jLabelCheckValue)
                    .addComponent(jLabelComboValue)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTextValue)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabelMessage)
                            .addComponent(jLabelMessageValue))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCheckBoxEatAtJoes)
                            .addComponent(jLabel5)
                            .addComponent(jLabelCheckValue))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButtonRed)
                            .addComponent(jRadioButtonBlue)
                            .addComponent(jRadioButtonGreen)
                            .addComponent(jLabel6)
                            .addComponent(jLabelRadioValue))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBoxAnimals, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(jLabelComboValue))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextFieldMessage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabelTextValue)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton1)
                            .addComponent(jLabel3))))
                .addContainerGap(43, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // This code demonstrates how to read from controls.
        this.jLabelMessageValue.setText(this.jLabelMessage.getText());
        this.jLabelCheckValue.setText(String.format("%s",this.jCheckBoxEatAtJoes.isSelected()));
        this.jLabelTextValue.setText(this.jTextFieldMessage.getText());
        this.jLabelComboValue.setText(this.jComboBoxAnimals.getSelectedItem().toString());
        // getting the radio button value is harder
       String selected = "";
       if (this.jRadioButtonBlue.isSelected()) {
           selected = this.jRadioButtonBlue.getText();
       } else if (this.jRadioButtonRed.isSelected()) {
           selected = this.jRadioButtonRed.getText();
       } else {
           selected = this.jRadioButtonGreen.getText();
       }      
        this.jLabelRadioValue.setText(selected);
            
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DemoSwingControlsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DemoSwingControlsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DemoSwingControlsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DemoSwingControlsJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DemoSwingControlsJFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.ButtonGroup jButtonGroupColors;
    private javax.swing.JCheckBox jCheckBoxEatAtJoes;
    private javax.swing.JComboBox jComboBoxAnimals;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelCheckValue;
    private javax.swing.JLabel jLabelComboValue;
    private javax.swing.JLabel jLabelMessage;
    private javax.swing.JLabel jLabelMessageValue;
    private javax.swing.JLabel jLabelRadioValue;
    private javax.swing.JLabel jLabelTextValue;
    private javax.swing.JRadioButton jRadioButtonBlue;
    private javax.swing.JRadioButton jRadioButtonGreen;
    private javax.swing.JRadioButton jRadioButtonRed;
    private javax.swing.JTextField jTextFieldMessage;
    // End of variables declaration//GEN-END:variables
}
